/******************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
*/
/******************************************************************************/
/** \file main.c
 **
 ** A detailed description is available at
 ** @link Sample Group Some description @endlink
 **
 **   1. 
 **
 ******************************************************************************/
//#ifdef RTOS 

//#include "FreeRTOS.h"
//#include "task.h"
//#include "timers.h"
//#include "queue.h"
//#include "semphr.h"
//#include "event_groups.h"
//#include "FreeRTOSConfig.h"

//#endif

//#include "gpio.h"
//#include "adc.h"
//#include "bgr.h"
//#include "dmac.h"
//#include "base_types.h"
//#include "nb.h"

#include "main.h"

void  Main_Queue_create(void);

static void Gpio_Config(void);
 
void vTask_send(void *pvParameters)
{
	//ATClient_Init();
	while (1)
    {		
	    //xSemaphoreGive( F_RspWaiting_BinarySemaphore );
		SEGGER_RTT_printf(0, "printf Test: %%c,         'S' : %c.\r\n", 'S');
		SEGGER_RTT_printf(0, "printf Test: %%5c,        'E' : %5c.\r\n", 'E');
		SEGGER_RTT_printf(0, "printf Test: %%-5c,       'G' : %-5c.\r\n", 'G');
		SEGGER_RTT_printf(0, "printf Test: %%5.3c,      'G' : %-5c.\r\n", 'G');
		SEGGER_RTT_printf(0, "printf Test: %%.3c,       'E' : %-5c.\r\n", 'E');
		SEGGER_RTT_printf(0, "printf Test: %%c,         'R' : %c.\r\n", 'R');

		SEGGER_RTT_printf(0, "printf Test: %%s,      \"RTT\" : %s.\r\n", "RTT");
		SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\\r\\nRocks.\" : %s.\r\n", "RTT\r\nRocks.");

		SEGGER_RTT_printf(0, "printf Test: %%u,       12345 : %u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%+u,      12345 : %+u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%.3u,     12345 : %.3u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%.6u,     12345 : %.6u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%6.3u,    12345 : %6.3u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%8.6u,    12345 : %8.6u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%08u,     12345 : %08u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%08.6u,   12345 : %08.6u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%0u,      12345 : %0u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%-.6u,    12345 : %-.6u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%-6.3u,   12345 : %-6.3u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%-8.6u,   12345 : %-8.6u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%-08u,    12345 : %-08u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%-08.6u,  12345 : %-08.6u.\r\n", 12345);
		SEGGER_RTT_printf(0, "printf Test: %%-0u,     12345 : %-0u.\r\n", 12345);

		SEGGER_RTT_printf(0, "printf Test: %%u,      -12345 : %u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%+u,     -12345 : %+u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%.3u,    -12345 : %.3u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%.6u,    -12345 : %.6u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%6.3u,   -12345 : %6.3u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%8.6u,   -12345 : %8.6u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%08u,    -12345 : %08u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%08.6u,  -12345 : %08.6u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%0u,     -12345 : %0u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-.6u,   -12345 : %-.6u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-6.3u,  -12345 : %-6.3u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-8.6u,  -12345 : %-8.6u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-08u,   -12345 : %-08u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-08.6u, -12345 : %-08.6u.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-0u,    -12345 : %-0u.\r\n", -12345);

		SEGGER_RTT_printf(0, "printf Test: %%d,      -12345 : %d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%+d,     -12345 : %+d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%.3d,    -12345 : %.3d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%.6d,    -12345 : %.6d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%6.3d,   -12345 : %6.3d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%8.6d,   -12345 : %8.6d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%08d,    -12345 : %08d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%08.6d,  -12345 : %08.6d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%0d,     -12345 : %0d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-.6d,   -12345 : %-.6d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-6.3d,  -12345 : %-6.3d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-8.6d,  -12345 : %-8.6d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-08d,   -12345 : %-08d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-08.6d, -12345 : %-08.6d.\r\n", -12345);
		SEGGER_RTT_printf(0, "printf Test: %%-0d,    -12345 : %-0d.\r\n", -12345);

		SEGGER_RTT_printf(0, "printf Test: %%x,      0x1234ABC : %x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%+x,     0x1234ABC : %+x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%.3x,    0x1234ABC : %.3x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%.6x,    0x1234ABC : %.6x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%6.3x,   0x1234ABC : %6.3x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%8.6x,   0x1234ABC : %8.6x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%08x,    0x1234ABC : %08x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%08.6x,  0x1234ABC : %08.6x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%0x,     0x1234ABC : %0x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%-.6x,   0x1234ABC : %-.6x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%-6.3x,  0x1234ABC : %-6.3x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%-8.6x,  0x1234ABC : %-8.6x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%-08x,   0x1234ABC : %-08x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%-08.6x, 0x1234ABC : %-08.6x.\r\n", 0x1234ABC);
		SEGGER_RTT_printf(0, "printf Test: %%-0x,    0x1234ABC : %-0x.\r\n", 0x1234ABC);
		
		SEGGER_RTT_WriteString(0, "###### Testing SEGGER_printf() ######\r\n");
		
		vTaskDelay(1500);  
    }
}
 
void vTask_Rx_handle(void *pvParameters)
{
    while (1)
    {
		//APP_infrared_ReadData();
		vTaskDelay(800); 
		SEGGER_RTT_printf(0, "Hello world !\r\n");  // 原接口
    }
}


// void  Main_Queue_create(void)
//{
////    nbiot_Queue_data_tx = xQueueCreate(100, sizeof(uint8_t));
////	nbiot_Queue_info   = xQueueCreate(20, sizeof(uint8_t));
////    vSemaphoreCreateBinary(F_RspWaiting_BinarySemaphore);
//}

 
int32_t main(void)
{
	Gpio_Config();
	SEGGER_RTT_Init();
	//SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
	//SEGGER_RTT_WriteString(0, "###### SEGGER_printf() Tests done. ######\r\n");

	SEGGER_RTT_printf(0, "Hello world !\r\n");  // 原接口
	
	xTaskCreate(vTask_send, "vTask_send", 100, NULL, 1, NULL);           
 	xTaskCreate(vTask_Rx_handle, "vTask_Rx_handle", 300, NULL,2, NULL);
	vTaskStartScheduler();                   /* 启动任务调度 */
	
	while(1);
}




//   nbiot_Datatx_Queue =  xQueueCreate(100, sizeof(uint8_t));  //创建队列，给予发送数据用
//	 nbiot_Datatx_info_Queue  = xQueueCreate(20, sizeof(uint8_t)); //创建队列，给予发送数据的信息用
//	 nbiot_Datarx_Queue  = xQueueCreate(512, sizeof(uint8_t)); //创建队列，给予发送数据的信息用
//	
//	 infrared_Datarx_Queue   = xQueueCreate(50, sizeof(uint8_t)); //创建队列
//	
//	 vSemaphoreCreateBinary(F_RspWaiting_BinarySemaphore);  //创建队列，给予发送标志位用
	
//	 vSemaphoreCreateBinary(infrared_BinarySemaphore);  //创建队列，给予发送标志位用	

/******************************************************************************
 * EOF (not truncated)
 ******************************************************************************/

/* CPU IO口配置（包含LED灯和按键的配置）*/
static void Gpio_Config(void)
{
    stc_gpio_cfg_t stcGpioCfg;
	
    Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE);     /* 打开GPIO外设时钟门控 */
    
    stcGpioCfg.enDir = GpioDirIn;                               ///< 端口方向配置->输入    
    stcGpioCfg.enDrv = GpioDrvL;                                ///< 端口驱动能力配置->高驱动能力    
    stcGpioCfg.enPu = GpioPuDisable;                            ///< 端口上下拉配置->无
    stcGpioCfg.enPd = GpioPdDisable;    
    stcGpioCfg.enOD = GpioOdDisable;                            ///< 端口开漏输出配置->开漏输出关闭    
    stcGpioCfg.enCtrlMode = GpioAHB;                            ///< 端口输入/输出值寄存器总线控制模式配置->AHB    
    Gpio_Init(GpioPortA, GpioPin7, &stcGpioCfg);        		///< GPIO IO USER KEY初始化    
    
    stcGpioCfg.enDir = GpioDirOut;                              ///< 端口方向配置->输出(其它参数与以上（输入）配置参数一致)    
    stcGpioCfg.enPu = GpioPuDisable;                            ////< 端口上下拉配置->无
    stcGpioCfg.enPd = GpioPdDisable;    
    //Gpio_Init(STK_LED_PORT, STK_LED_PIN, &stcGpioCfg);          ///< GPIO IO LED端口初始化
    //Gpio_ClrIO(STK_LED_PORT, STK_LED_PIN);                      ///< LED关闭
}
